﻿/// <reference path="../../../EditedVersion/SinglePageApp/libs/protoClass.js" />
/// <reference path="../../../EditedVersion/SinglePageApp/libs/knockout-2.2.1.js" />
/// <reference path="../../../EditedVersion/SinglePageApp/scripts/GridView.js" />
/// <reference path="../../../EditedVersion/SinglePageApp/scripts/TripDetails.js" />

describe("Grid view", function () {
    var offer1, offer2, offer3;
    var driver1, driver2, driver3;
    var viewModel;

    beforeEach(function () {
        var allOffers = [];
        var bmw = new TripDetails.Vehicle("Автомобил", "Bmw", 2002, 4, 7);
        var mercedes = new TripDetails.Vehicle("Автомобил", "Mercedes", 2000, 4, 9);
        driver1 = new TripDetails.Driver("Ивелин", "Соколов", "asokolov@gmail.com", "4357456", 27, "Мъж", bmw, undefined, undefined);
        driver2 = new TripDetails.Driver("Андрей", "Соколов", "isokolov@gmail.com", "4548991", 19, "Мъж", mercedes, undefined, undefined);
        driver3 = new TripDetails.Driver("Мая", "Пенчева", "maq.pencheva@gmail.com", "2346680", 25, "Жена", bmw, undefined, undefined);

        offer1 = new TripDetails.Offer(
            driver1,
            new TripDetails.Price(22, "Lv."),
            new TripDetails.Trip("София", "Варна", "07/12/2013"));
        allOffers.push(offer1);

        offer2 = new TripDetails.Offer(
            driver2,
            new TripDetails.Price(31, "Lv."),
            new TripDetails.Trip("София", "Стара Загора", "06/21/2013"));
        allOffers.push(offer2);

        offer3 = new TripDetails.Offer(
            driver3,
            new TripDetails.Price(12, "$"),
            new TripDetails.Trip("Бургас", "Стара Загора", "06/18/2013"));
        allOffers.push(offer3);

        viewModel = new OfferModel(allOffers);
        ko.applyBindings(viewModel)
    });

    it("removing an offer is successful", function () {
        viewModel.removeOffer(offer2);
        var expected = offer1.toString() + "\n" +
            offer3.toString() + "\n";
        var actual = viewModel.toString();
        expect(actual).toBe(expected);
    });

    it("sorting offers by price is successful", function () {
        viewModel.sortColumn("Цена");
        var expected = offer3.toString() + "\n" +
            offer1.toString() + "\n" +
            offer2.toString() + "\n";
        var actual = viewModel.toString();
        expect(actual).toBe(expected);
    });

    it("sorting offers by price and reversing is sucessful", function () {
        viewModel.sortColumn("Цена");
        viewModel.sortColumn("Цена");
        var expected = offer2.toString() + "\n" +
            offer1.toString() + "\n" +
            offer3.toString() + "\n";
        var actual = viewModel.toString();
        expect(actual).toBe(expected);
    });

    it("sorting offers by driver's info is successful", function () {
        viewModel.sortColumn("Информация за шофьора:");
        var expected = offer2.toString() + "\n" +
            offer1.toString() + "\n" +
            offer3.toString() + "\n";
        var actual = viewModel.toString();
        expect(actual).toBe(expected);
    });
});